package login;

import com.sun.scenario.Settings;

import javax.swing.JFrame;
import javax.swing.JPanel;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class login {
    public login() {
        JButton button_ok, button_cancle;
        JTextField textField_userName;
        JPanel nn;
        JFrame nw = new JFrame("登录");
        JPasswordField passwordField_password;
        //用户名
        JLabel a1 = new JLabel("用户名:");
        a1.setFont(new Font("宋体", Font.PLAIN, 30));
        a1.setBounds(54, 105, 137, 45);
        //用户名编辑框
        textField_userName = new JTextField(20);
        textField_userName.setFont(new Font("宋体", Font.PLAIN, 26));
        textField_userName.setBounds(195, 111, 223, 29);
        nn = new JPanel();
        //确定
        button_ok = new JButton("确定");
        button_ok.setFont(new Font("宋体", Font.PLAIN, 26));
        button_ok.setBounds(130, 240, 100, 59);
        //取消
        button_cancle = new JButton("取消");
        button_cancle.setFont(new Font("宋体", Font.PLAIN, 26));
        button_cancle.setBounds(340, 240, 100, 59);
        nn.setLayout(null);
        //密码
        JLabel label_password = new JLabel("密  码:");
        label_password.setFont(new Font("宋体", Font.PLAIN, 30));
        label_password.setBounds(54, 153, 126, 29);
        nn.add(label_password);
        //密码输入框
        passwordField_password = new JPasswordField(20);
        passwordField_password.setFont(new Font("宋体", Font.PLAIN, 26));
        passwordField_password.setBounds(195, 153, 223, 29);
        nn.add(a1);
        nw.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        nn.add(textField_userName);
        nn.add(passwordField_password);
        nn.add(button_ok);
        nn.add(button_cancle);
        JMenuBar mb = new JMenuBar();
        nw.getContentPane().add(nn);
        JMenu mn = new JMenu("菜单");
        mn.setFont(new Font("宋体", Font.PLAIN, 26));
        mn.setBounds(0, 130, 64, 24);
        nn.add(mn);
        mb.add(mn);
        setBackground(nn);
        nw.setJMenuBar(mb);
        //注册
        JMenuItem regist = new JMenuItem("注册");
        regist.setFont(new Font("宋体", Font.PLAIN, 26));
        //注销
        JMenuItem zx = new JMenuItem("注销");
        zx.setFont(new Font("宋体", Font.PLAIN, 26));
        mn.add(regist);
        mn.add(zx);
        button_ok.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String name = (textField_userName.getText());
                String passwords = (passwordField_password.getText());
            	dbhelper db=new dbhelper();
            	db.login(name,passwords,nw);
            }
        });
        button_cancle.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                textField_userName.setText("");
                passwordField_password.setText("");
            }
        });
        regist.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                regist z1=new regist();
            }
        });
        zx.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                //zx1 z1=new zx1();
            }
        });
        //设置窗口的大小和位置
        nw.setSize(600, 600);
        nw.setLocation(420, 120);
        nw.setVisible(true);
    }
    public static void setBackground(JPanel f)
    {
        ImageIcon image=new ImageIcon("H:\\exam_back.jpeg");//随便找一张图就可以看到效果。
        JLabel jl=new JLabel(image);
        jl.setBounds(0, 0, 600, 600);
        f.add(jl);
    }
    public static void main(String[] args) {
        new login();
    }
}
